#include <bits/stdc++.h>
using namespace std;
int t,d[100005],v1[100005],a[100005],mqq[100005],maxn,a1,a2;
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    while(t--)
    {
        int n,m,l,v;
        cin>>n>>m>>l>>v;
        for (int i=1;i<=n;i++)
        {
            cin>>d[i]>>v1[i]>>a[i];
        }
        for (int i=1;i<=m;++i)
        {
            cin>>mqq[i];
            maxn=max(maxn,mqq[i]);
        }
        for (int i=1;i<=n;i++)
        {
            if(d[i]<=maxn && v1[i]>v)
            {
                a1++;
            }
        }
        if(a1==0)
        {
            a2=m;
        }
        else
        {
            a2=m-1;
        }
        cout<<a1<<" "<<a2<<endl;

    }
    return 0;
}
